# -*- coding: utf-8 -*-
from sqlalchemy.schema import *
from sqlalchemy.types import *
from sqlalchemy.orm import *
from pythonblog.model import meta

class Section(meta.Base):
    __tablename__ = 'section'
    
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(50), nullable=False, unique=True)
    path = Column(Unicode(50), nullable=False, unique=True)
    message = Column(Unicode(500))
    """ add section logo image """
    parent_id = Column(Integer, ForeignKey('section.id'))
    sub_sections = relation('Section', lazy=False, join_depth=2, order_by=id, 
                            backref=backref('parent', remote_side='Section.id'))
                        
    posts = relation('Post', lazy='dynamic', order_by='desc(Post.createDate)')
        
    def __repr__(self):
        return u'<Section "%s">' % self.name

class PostType(meta.Base):
    __tablename__ = 'post_type'

    id = Column(Integer, primary_key=True)
    name = Column(Unicode(50), nullable=False, unique=True)
    path = Column(Unicode(50), nullable=False, unique=True)

    def __repr__(self):
        return u'<PostType "%s">' % self.name